<%@ include file="/en/jsp/static.jsp" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>

<%
  String SUBJECT = (String) request.getAttribute("SUBJECT");
  String DESCRIPTION = (String) request.getAttribute("DESCRIPTION");

  int END_YEAR = Integer.parseInt((String)request.getAttribute("END_YEAR"));
  int END_MONTH = Integer.parseInt((String)request.getAttribute("END_MONTH"));
  int END_DAY = Integer.parseInt((String)request.getAttribute("END_DAY"));

  int MULTIPLE = Integer.parseInt((String)request.getAttribute("MULTIPLE"));
  int SHOWVOTER = Integer.parseInt((String)request.getAttribute("SHOWVOTER"));
  int SHOWRESULT = Integer.parseInt((String)request.getAttribute("SHOWRESULT"));
  int SENDRESULT = Integer.parseInt((String)request.getAttribute("SENDRESULT"));
  int MANUALCONCLUDE = Integer.parseInt((String)request.getAttribute("MANUALCONCLUDE"));

  int ID = Integer.parseInt((String)request.getAttribute("ID"));
%>

<script LANGUAGE="JavaScript">
function onAdd()
{
  var choice = document.theForm.CHOICE.value;
  if ( choice != null && choice.length > 0 )
  {
    var option = new Option(choice, choice);
    document.theForm.CHOICES.options[document.theForm.CHOICES.length] = option;
    document.theForm.CHOICE.value = "";
    document.theForm.CHOICE.focus();
  }
}

function onRemove()
{
  var options = document.theForm.CHOICES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      if (options[i].selected == true)
        options[i] = null;
    }
  }
//	document.theForm.CHOICES.focus();
}

//select all the items so they will be sent out
function onSubmit()
{
//	alert("Set selected");
  var options = document.theForm.CHOICES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      options[i].selected = true;
    }
//		alert("Set selected");
  }
}
</script>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>


<form action="<%=BoxStatic.servletDir%>BoxPollAction" method=post name=theForm >
<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
      &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> -
  <%
    if ( ID == 0 )
      out.print("Create New Poll");
    else
      out.print("Edit and Restart Poll");
  %>
      </b>
    </td>
    <td align=right>
      <a href="<%=BoxStatic.jspDir%>poll/BoxPoll.jsp">
        View Poll List
      </a>
    </td>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width= "100%" border=0 cellspacing=1 cellpadding=1 bgcolor=#e0e0e0 style="font-size:16px">
  <tr  bgColor=#7EC1F3><td>
    <input type=submit value=
<%
      if (ID==0)
        out.println("\"Create\" name=SubmitSave onclick=\"onSubmit()\" ");
      else
      {
        out.println("\"Update and Restart\" name=SubmitUpdate onclick=\"onSubmit()\"  >");
        out.println("<input type=submit value=\"Delete\" name=SubmitDelete");
      }
%>
            >
    <input type=submit value="Cancel" name=SubmitCancel>
  </td></tr>
  <tr><td>
    <table border=0 width="100%" cellspacing=0 cellpadding=0>
      <input type=hidden name=ID value=<%=ID%>>
      <tr><td>
        <b>Subject:</b> <input align=right type=text name=SUBJECT size=50 maxlength=80 value="<%=SUBJECT%>">
      </td></tr>
      <tr><td>
        <b>Description:</b><br>
        <textarea name=DESCRIPTION rows=3 cols=60><%=DESCRIPTION%></textarea><br>
      </td></tr>
      <tr><td>
        <input type=text name="CHOICE" size=40 maxlength=200>
        <input type="button" value="Add Choice" name="Add" onclick="onAdd()">
      </td></tr>
      <tr><td>
        <select name="CHOICES" size="5" multiple>
<%
if ( ID != 0 )
{
  linuxbox.poll.logic.BoxPoll home = new linuxbox.poll.logic.BoxPoll();
  java.util.Iterator it = home.getChoices(ID);
%>
          <common:Iteration name="entry" type="linuxbox.poll.logic.BoxPollChoiceEntry" group="<%=it%>">
          <option value=<%=entry.getChoice()%>><%=entry.getChoice()%></option>
          </common:Iteration>
<%
}
%>
        </select>
      </td></tr>
      <tr><td>
        <input type="button" value="Remove Selected Choices" name="Remove" onclick="onRemove()">
      </td></tr>
    </table>
  </td></tr>
  <tr><td>
    <table border=0 width="100%" cellspacing=1 cellpadding=1>
      <tr bgColor=#7EC1F3><td colspan=2>
        <b><font size="+1">Select additional options</font></b>
      </td></tr>
      <tr align="left" valign="top">
        <td width="1%" nowrap>
          <b>Selections</b><br>
          <input type="radio" name="MULTIPLE" value=0 <% if (MULTIPLE==0) out.print("checked"); %> >
            Vote for one choice<br>
          <input type="radio" name="MULTIPLE" value=1 <% if (MULTIPLE!=0) out.print("checked"); %> >
            Vote for one or more choices
        </td>
        <td>
          <b>Poll results</b><br>
          <input type=radio name="SHOWRESULT" value=0 <% if (SHOWRESULT==0) out.print("checked"); %> >
            Display results when poll is closed<br>
          <input type=radio name="SHOWRESULT" value=1 <% if (SHOWRESULT!=0) out.print("checked"); %> >
            Display results during polling
        </td>
      </tr>
      <tr>
        <td width="1%" nowrap>
          <b>Voter identity</b><br>
          <input type=radio name="SHOWVOTER" value=0 <% if (SHOWVOTER==0) out.print("checked"); %> >
            Do not display voter identity<br>
          <input type=radio name="SHOWVOTER" value=1 <% if (SHOWVOTER!=0) out.print("checked"); %> >
            Display voter identity with each vote
        </td>
        <td>
          <b>Conclude poll</b><br>
          <input type=radio name="MANUALCONCLUDE" value=1 <% if (MANUALCONCLUDE!=0) out.print("checked"); %> >
            Manually<br>
          <input type=radio name="MANUALCONCLUDE" value=0 <% if (MANUALCONCLUDE==0) out.print("checked"); %> >
           On <select name="END_MONTH" size="1">
                <common:MonthList selected="<%=END_MONTH%>" allownull="false" />
              </select>
              <select name="END_DAY" size="1">
                <common:DayList selected="<%=END_DAY%>" allownull="false" />
              </select>
              <select name="END_YEAR" size="1">
                <common:YearList selected="<%=END_YEAR%>" allownull="false" />
              </select>
        </td>
      </tr>
      <tr>
        <td colspan=2>
          <b>Results distribution</b><br>
          <input type=radio name="SENDRESULT" value=0 <% if (SENDRESULT==0) out.print("checked"); %> >
            Do not send any results<br>
          <input type=radio name="SENDRESULT" value=1 <% if (SENDRESULT==1) out.print("checked"); %> >
            Send results to all the voters via email<br>
          <input type=radio name="SENDRESULT" value=2 <% if (SENDRESULT==2) out.print("checked"); %> >
            Send results to the person who created the poll via email
        </td>
      </tr>
      <tr><td colspan=2>
          <input type=submit value=
<%
    if (ID==0)
      out.println("\"Create\" name=SubmitSave onclick=\"onSubmit()\" ");
    else
    {
      out.println("\"Update and Restart\" name=SubmitUpdate onclick=\"onSubmit()\"  >");
      out.println("<input type=submit value=\"Delete\" name=SubmitDelete");
    }
%>
          >
          <input type=button value="Cancel" onclick="window.history.go(-1)" >
        </td></tr>
    </table>
  </td></tr>
</table>

<hr width=\"100%\" color=#E06000 align=left>
</form>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
